home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / MARK.ASM < prev    next >
Assembly Source File  |  1996-01-20  |  4KB  |  181 lines

  1. ; MARK.ASM for E32 - Copyright (C) 1994 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. include    model.inc
  5.  
  6. public    mark, cut, copy, paste, pastesiz
  7. extrn    rowcount:near
  8. extrn    locate:near, working:near
  9. extrn    sub_push:near
  10. extrn    error:near
  11. extrn    working:near
  12. extrn    display_bottom:near
  13. extrn    open_space:near
  14. extrn    memcopy:near
  15.  
  16. include    dataseg.inc
  17. extrn    count_start:dword, file_row:dword
  18. extrn    mark_mode:byte, mark_home:dword, mark_start:dword
  19. extrn    mark_end:dword, cursor:dword
  20. extrn    dirty_bits:byte, filesiz:dword, push_mode:byte
  21. extrn    cur_posn:word
  22.  
  23. pasteptr    dd 0
  24. pastesiz    dd 0
  25.  
  26. cut_proc    dd alloc_paste
  27.  
  28. @curseg    ends
  29.  
  30. include    codeseg.inc
  31. ;
  32. ; toggle the mark state and resets the paste buffer pointers
  33. ;
  34. mark    proc    near
  35.     xor    eax,eax
  36.     not    mark_mode    ; toggle the mode flag
  37.     cmp    mark_mode,al    ; turning mode on?
  38.     jne    short mark_on
  39.     or    dirty_bits,1    ; need to redraw the screen
  40.     mov    mark_end,eax
  41.     dec    eax        ; 0FFFFFFFFh
  42.     mov    mark_start,eax
  43.     jmp    short mark_ret
  44. mark_on:
  45.     mov    eax,cursor    ; get the cursor offset
  46.     mov    mark_start,eax    ; start of marked range
  47. mark_ret:
  48.     mov    mark_end,eax    ; end of marked range
  49.     mov    mark_home,eax    ; center of marked range
  50.     clc
  51.     ret
  52. mark    endp
  53.  
  54. ;
  55. ; remove marked text; copy to paste buffer
  56. ;
  57. cut    proc    near
  58.     cmp    mark_mode,0    ; is the mark mode on?
  59.     je    no_mark        ; if not, then do nothing
  60.     call    copy_marked    ; sets up cut_proc
  61.     jc    short no_mark    ; exit if too big
  62.     call    sub_push    ; adjust push_offset if nessesary
  63.  
  64.     mov    esi,mark_end    ; source
  65.     mov    edi,mark_start    ; target
  66.     xor    ecx,ecx
  67.     mov    [count_start],ecx
  68.     mov    eax,edi        ; mark_start
  69.     mov    [count_start+4],eax
  70.  
  71.     inc    ecx
  72.     mov    [file_row],ecx
  73.     mov    ecx,[filesiz]
  74.     sub    ecx,esi        ; ESI = mark_end
  75.                 ; ECX = bytes to move down
  76.  
  77. ; update file buffer
  78.     mov    eax,pastesiz
  79.     sub    filesiz,eax    ; EAX = block size
  80.     call    working
  81.     push    ds
  82.     push    es
  83.     mov    ax,fs
  84.     mov    es,ax
  85.     mov    ds,ax
  86.     call    memcopy
  87.     pop    es
  88.     pop    ds
  89.  
  90. ; move cursor to mark_start
  91.     mov    esi,mark_start
  92.     mov    cursor,esi
  93.     mov    dx,cur_posn
  94.     call    locate        ; adjust the screen position
  95.  
  96. cut_exit:
  97.     call    mark        ; this turns off select
  98. sizof_call    equ    $-cut_exit
  99.     or    dirty_bits,10000001b
  100.     call    rowcount+sizof_call
  101. no_mark:clc
  102.     ret
  103. cut    endp
  104.  
  105. copy    proc    near
  106.     cmp    mark_mode,0    ; is the mark mode on?
  107.     je    short no_copy    ; if not, then do nothing
  108.     call    copy_marked
  109.     jc    short no_copy
  110.     call    mark        ; turn mark mode off
  111.     
  112. no_copy:
  113.     clc
  114.     ret
  115. copy    endp
  116.  
  117. paste    proc    near
  118.     mov    ecx,pastesiz    ; number of characters in buffer
  119.     jecxz    no_paste    ; if zero, nothing to paste
  120.  
  121.     push    es
  122.     mov    eax,ecx
  123.     call    open_space
  124.     mov    ecx,pastesiz
  125.     mov    edi,cursor    ; ES:[EDI] -> space in file buffer
  126.     mov    esi,pasteptr
  127.     call    memcopy
  128.     pop    es
  129.     call    display_bottom    ; update screen from cursor to screen bottom
  130.  
  131. no_paste:
  132.     clc
  133.     ret
  134.  
  135. paste    endp
  136.  
  137. ;
  138. ; used locally by CUT and COPY
  139. ;
  140. copy_marked:
  141.  
  142.     push    ds
  143.     push    es
  144.     jmp    cut_proc
  145. copy0:
  146.     mov    ecx,mark_end    ; get end of mark region
  147.     sub    ecx,mark_start
  148.  
  149.     push    ecx
  150.     mov    esi,pasteptr
  151.     mov    ebx,ecx        ; bytes wanted
  152.     sys    ResMemNear    ; resize buffer
  153.     pop    ecx
  154.     jc    short copy_exit
  155.     mov    pasteptr,esi
  156.     mov    eax,ecx
  157.  
  158.     push    ds
  159.     pop    es
  160.     mov    edi,pasteptr    ; ES:[EDI] -> paste buffer
  161.     mov    esi,mark_start
  162.     mov    pastesiz,ecx    ; save block size
  163.     push    fs
  164.     pop    ds        ; DS:[ESI] -> marked block
  165.     call    memcopy
  166.  
  167. copy_exit:
  168.     pop    es
  169.     pop    ds
  170.     ret
  171.  
  172. alloc_paste:
  173.     mov    cut_proc,offset @curseg:copy0
  174.     mov    ebx,1024    ; initial block size
  175.     sys    GetMemNear
  176.     mov    pasteptr,esi
  177.     jmp    copy0
  178.  
  179. @curseg    ends
  180.     end
  181.